package cn.com.nes.site.handle.serializer;

import cn.com.nes.site.entity.em.IEnum;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.io.Serializable;

public class EnumSerializer<T extends IEnum> extends JsonSerializer<IEnum> implements Serializable {

    @Override
    public void serialize(IEnum iEnum, JsonGenerator jsonGenerator,
            SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        jsonGenerator.writeString(iEnum == null ? null : iEnum.getKey().toString());
    }

}
